import { BuffEffect, EffectCondition, EffectType, Effect_tag } from "../shared/interface";
import { Tpl_skillInfo } from "../shared/master/MsgAction";
import func from "./func";

/**
 * 技能效果描述解析
 */
const icons = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟']
export default function (data: Tpl_skillInfo) {
    let _outStr = ''
    if (data.effectVal.length == 0) {
        return data.desc;
    }
    for (let i = 0; i < data.effectVal.length; i++) {
        let outStr = ``;
        let numStr = `${icons[i]}`;
        const item = data.effectVal[i];
        let hitType = item.EffectType;
        let server_val = item.val;
        let rang = item.rang;
        let time = item.time;
        let condition = getCondition(item.EffectCondition);
        let tag = getTagName(item.tag);
        let buffKey;
        switch (hitType) {
            case EffectType.召唤永久单位:
                outStr = `✡️召唤${item.create_name}参与战斗`
                break;
            case EffectType.屏障:
                if (rang > 1) {
                    outStr = `为${rang}个${tag}生成${server_val}点生命屏障`
                } else {
                    outStr = `对${tag}生成${server_val}点生命屏障`
                }
                break;
            case EffectType.对目标造成物理伤害:
                if (rang > 1) {
                    outStr = `对${rang}个${tag}造成${server_val}物理伤害⚔️`
                } else {
                    outStr = `对${tag}造成${server_val}物理伤害⚔️`
                }
                break;
            case EffectType.对目标造成魔法伤害:
                if (rang > 1) {
                    outStr = `对${rang}个${tag}造成${server_val}魔法伤害🪄`
                } else {
                    outStr = `对${tag}造成${server_val}魔法伤害🪄`
                }
                break;
            case EffectType.沉默单体:
                outStr = `使${tag}沉默${server_val}秒,沉默时无法使用技能`
                break;
            case EffectType.真实伤害:
                outStr = `使${tag}${rang}个单位造成${server_val}真实伤害☢️`
                break;
            case EffectType.增加金币:
                outStr = `使${tag}💰金币+${func.BN(server_val)}`
                break;
            case EffectType.永久增加最大生命值:
                outStr = `永久增加自身${server_val}点最大生命❤`
                break;
            case EffectType.恢复目标生命值:
                if (rang > 1) {
                    outStr = `对${rang}个${tag}恢复${server_val}点生命❤`
                } else {
                    outStr = `恢复${tag}恢复${server_val}点生命❤`

                }
                break;

            default:
                break;
        }

        // buff 检查
        if (!outStr) {
            switch (hitType) {
                case EffectType.buff_提升物理吸血:
                    buffKey = BuffEffect.物理吸血
                    break;
                case EffectType.buff_提升生命恢复:
                    buffKey = BuffEffect.生命恢复速度
                    break;
                case EffectType.buff_提升最大魔法值:
                    buffKey = BuffEffect.最大魔法值
                    break;
                case EffectType.buff_提升魔法值恢复速度:
                    buffKey = BuffEffect.魔法恢复速度
                    break;
                case EffectType.buff_提升最小物攻:
                    buffKey = BuffEffect.最小物攻
                    break;
                case EffectType.buff_提升最大物攻:
                    buffKey = BuffEffect.最大物攻
                    break;
                case EffectType.buff_提升攻击速度:
                    buffKey = BuffEffect.攻击速度
                    break;
                case EffectType.buff_提升最大魔攻:
                    buffKey = BuffEffect.最大魔攻
                    break;
                case EffectType.buff_提升最小魔攻:
                    buffKey = BuffEffect.最小魔攻
                    break;
                case EffectType.buff_提升魔法防御:
                    buffKey = BuffEffect.魔法防御
                    break;
                case EffectType.buff_提升物理防御:
                    buffKey = BuffEffect.物理防御
                    break;
                case EffectType.buff_提升魔法暴击率:
                    buffKey = BuffEffect.魔法暴击率
                    break;
                case EffectType.buff_提升物理暴击率:
                    buffKey = BuffEffect.物理暴击率
                    break;
                case EffectType.buff_提升魔法吸血:
                    buffKey = BuffEffect.魔法吸血
                    break;
                case EffectType.buff_提升最大生命:
                    buffKey = BuffEffect.最大生命

                    break;

                default:
                    break;
            }
            outStr = `🔺提升${server_val}点${buffKey}`;
            if (time && item.EffectCondition != EffectCondition.auto_附带即生效) {
                outStr = `${outStr}持续${time}秒`
            }
        }


        if (data.effectVal.length == 1) {
            numStr = ''
        }
        if (condition.length == 0) {
            _outStr += `${numStr}${condition}${outStr}`
        } else {
            _outStr += `${condition}${outStr}`
        }
        outStr = '';
    }
    return _outStr;
}
function getCondition(condition: EffectCondition) {
    let str = '';
    switch (condition) {
        case EffectCondition.auto_普通攻击时:
            str = '普通攻击时'
            break;
        case EffectCondition.目标生命值高于百分之70:
            str = '目标生命>70%'
            break;
        case EffectCondition.auto_受到普通攻击时:
            str = '受到普通攻击时'
            break;
        case EffectCondition.auto_死亡时:
            str = '死亡时'
            break;
        default:
            break;
    }
    if (str.length > 0) {
        str = `🔃${str}|`
    }
    return str;
}
function getTagName(tag: Effect_tag) {
    let str = '未知目标'
    switch (tag) {
        case Effect_tag.友军:
            str = '友军'
            break;
        case Effect_tag.上一个效果的目标:
            str = '上一个效果的目标'
            break;
        case Effect_tag.敌人:
            str = '敌人'
            break;
        case Effect_tag.自己:
            str = '自己'
            break;
        case Effect_tag.无差别:
            str = '场上单位(包括友军)'
            break;
        default:
            break;
    }
    return str
}